package com.junlaninfo.HandwritingLock;

import com.sun.org.apache.bcel.internal.generic.NEW;

/**
 * Created by 辉 on 2020/8/23.
 */
public class Thread02 implements Runnable {
    private int count = 100;

    public void run() {
        while (count > 0) {
            ticket();
        }
    }

    private void ticket() {
        DaXiongLock lock = new DaXiongLock();

        if (count > 0) {
            lock.tryLock(); //获取锁
            System.out.println(Thread.currentThread().getName() + "正在售卖：" + (100 - count + 1) + "张票");
            count--;
            lock.unLock();//释放锁
        }
    }

    public static void main(String[] args) {
        Thread02 thread02 = new Thread02();
        Thread thread1 = new Thread(thread02, "窗口1");
        Thread thread2 = new Thread(thread02, "窗口2");
        Thread thread3 = new Thread(thread02, "窗口3");
        thread1.start();
        thread2.start();
        thread3.start();


    }
}
